﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.Xml.Serialization;


namespace SEOSitemap
{
    [Serializable()]
    [XmlRoot("urlset", Namespace="http://www.sitemaps.org/schemas/sitemap/0.9")]
    public class SiteMapDocument
    {
        private List<UrlItem> _urls;

        [XmlElement("url")]
        public List<UrlItem> Urls
        {
            get { return _urls; }
            set { _urls = value; }
        }

        private string _fileName;

        [XmlIgnore]
        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }

        public void AddUrl(string loc, DateTime lastmod, string priority, ChangeFrequency changefreq)
        {
            if (Urls == null)
            {
                Urls = new List<UrlItem>();
            }

            UrlItem urlItem = new UrlItem();
            urlItem.LastmodParsed = lastmod;
            urlItem.Loc = loc;
            urlItem.Priority = priority;
            urlItem.ChangeFreq = changefreq;
            Urls.Add(urlItem);

        }

        public void SaveToFile()
        {
            File.WriteAllText(FileName, ToXml());
        }

        public string ToXml()
        {
            return Helper.ToXml(this);
        }
    }
}
